package io.github.talelin.latticy.controller.api;


import io.github.talelin.autoconfigure.exception.NotFoundException;
import io.github.talelin.latticy.model.ArticleDO;
import io.github.talelin.latticy.model.CommentDO;
import io.github.talelin.latticy.service.ArticleService;
import io.github.talelin.latticy.service.CommentService;
import io.github.talelin.latticy.vo.CreatedVO;
import io.github.talelin.latticy.vo.DeletedVO;
import io.github.talelin.latticy.vo.PageResponseVO;
import io.github.talelin.latticy.vo.UpdatedVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Positive;

/**
* @author generator@lms
* @since 2021-04-23
*/
@RestController
@RequestMapping("/api/comment")
@Validated
public class CommentApiController {

    @Autowired
    private CommentService commentService;

    @Autowired
    private ArticleService articleService;

    //添加评论
    @PostMapping("")
    public CreatedVO create(@RequestBody CommentDO dto) {
        System.out.println(dto);
        ArticleDO article = articleService.getById(dto.getArticleId());
        if (article == null) {
            throw new NotFoundException(90000);
        }
        dto.setType(1);
        commentService.getBaseMapper().insert(dto);
        return new CreatedVO("评论成功！");
    }

}
